package com.beiming.libra.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.beiming.libra.common.Assert;
import com.beiming.libra.common.constants.ValidateMessage;
import com.beiming.libra.common.enums.ErrorCode;
import com.beiming.libra.common.enums.UserTypeEnum;
import com.beiming.libra.common.page.PageResult;
import com.beiming.libra.domain.ArbUserDetail;
import com.beiming.libra.domain.dto.requestdto.ArbUserRequestDTO;
import com.beiming.libra.domain.dto.requestdto.ArbUserSearchRequestDTO;
import com.beiming.libra.domain.dto.requestdto.SecretaryGeneralUserRequestDTO;
import com.beiming.libra.domain.dto.requestdto.UserRegisterInfoRequestDTO;
import com.beiming.libra.domain.dto.responsedto.UserResponseDTO;
import com.beiming.libra.helper.Result;
import com.beiming.libra.service.UserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
/**
 * 
 * @author weibo
 *
 */
@RestController
@Api(value = "用户信息模块", tags = "用户信息模块")
@RequestMapping("/api/user")
public class UserController {

  @Resource
  private UserService userService;

  /**
   * 根据userid获取用户信息
   */
  @ApiOperation(value = "根据用户id获取用户信息", notes = "根据用户id获取用户信息")
  @RequestMapping(value = "userId/{userId}", method = RequestMethod.GET)
  @ResponseBody
  public Result<UserResponseDTO> getUserById(@ApiParam(value = "用户id", required = true) @PathVariable String userId) {

    Assert.isNotEmpty(userId, ErrorCode.USER_ID_IS_EMPTY, ValidateMessage.USER_ID_NOT_BLANK);

    UserResponseDTO vo = userService.getUserById(userId);
    return Result.success(vo);
  }

  /**
   * 根据用户类型和电话号获取用户信息
   */
  @ApiOperation(value = "根据用户类型和电话号获取用户信息", notes = "根据用户类型和电话号获取用户信息")
  @RequestMapping(value = "userType/{userType}/phone/{phone}", method = RequestMethod.GET)
  @ResponseBody
  public Result<UserResponseDTO> getUserByTypeAndPhone(
      @ApiParam(value = "用户类型(PEOPLE[个人],COMPANY[企业],SPECIAL[专项用户],SECRETARY[办案秘书], ARBITRATION[仲裁员],FINANCE[财务],LEADER[领导],ADMIN[系统管理员])", required = true) @PathVariable UserTypeEnum userType,
      @ApiParam(value = "手机号", required = true) @PathVariable String phone) {

    Assert.isNotNull(userType, ErrorCode.USER_TYPE_IS_EMPTY, ValidateMessage.USER_TYPE_NOT_BLANK);
    Assert.isNotEmpty(phone, ErrorCode.MOBILE_PHONE_IS_EMPTY, ValidateMessage.MOBILE_PHONE_NOT_BLANK);

    UserResponseDTO vo = userService.getUserByPhoneAndType(phone, userType.getCode());
    return Result.success(vo);
  }

  /**
   * 根据用户类型获取用户信息
   */
  @ApiOperation(value = " 根据用户类型获取用户信息", notes = " 根据用户类型获取用户信息")
  @RequestMapping(value = "userType/{userType}", method = RequestMethod.GET)
  @ResponseBody
  public Result<List<UserResponseDTO>> getUserByType(
      @ApiParam(value = "用户类型(PEOPLE[个人],COMPANY[企业],SPECIAL[专项用户],SECRETARY[办案秘书], ARBITRATION[仲裁员],FINANCE[财务],LEADER[领导],ADMIN[系统管理员])", required = true) @PathVariable UserTypeEnum userType) {

    Assert.isNotNull(userType, ErrorCode.USER_TYPE_IS_EMPTY, ValidateMessage.USER_TYPE_NOT_BLANK);

    List<UserResponseDTO> ls = userService.getAllUserByType(userType.getCode());
    return Result.success(ls);
  }

  /**
   * 根据过滤条件（类型，地区，擅长领域，名字）查询查询仲裁员&办案秘书用户。。分页查询
   */
  @ApiOperation(value = " 根据过滤条件（类型，地区，擅长领域，名字）查询查询仲裁员&办案秘书用户。。分页查询", notes = "根据过滤条件（类型，地区，擅长领域，名字）查询查询仲裁员&办案秘书用户。。分页查询")
  @RequestMapping(value = "arb/list", method = RequestMethod.POST)
  @ResponseBody
  public Result<PageResult<ArbUserDetail>> listArbUser(@RequestBody @Valid ArbUserSearchRequestDTO dto) {
    PageResult<ArbUserDetail> ls = userService.listArbUser(dto);
    return Result.success(ls);
  }
  /**
   * 新增仲裁员&办案秘书
   */
  @ApiOperation(value = "新增仲裁员&办案秘书", notes = "新增仲裁员&办案秘书")
  @RequestMapping(value = "arb", method = RequestMethod.PUT)
  @ResponseBody
  public Result insertArb(@RequestBody @Valid ArbUserRequestDTO dto) {
    userService.insertArbUser(dto);
    return Result.success();
  }
  /**
   * 新增秘书长
   */
  @ApiOperation(value = "新增秘书长", notes = "新增秘书长")
  @RequestMapping(value = "generalUser", method = RequestMethod.PUT)
  @ResponseBody
  public Result insertGeneralUser(@RequestBody @Valid SecretaryGeneralUserRequestDTO dto) {
    userService.insertGeneralUser(dto);
    return Result.success();
  }
  
  /**
   * 新增普通用户
   */
  @ApiOperation(value = "新增普通用户", notes = "新增普通用户")
  @RequestMapping(value = "user", method = RequestMethod.PUT)
  @ResponseBody
  public Result insertUser(@RequestBody @Valid UserRegisterInfoRequestDTO dto) {
    userService.insertUser(dto);
    return Result.success();
  }
  
  

}
